package com.yesep.learn.design.behavioral.interpreter.sql;

import java.util.*;

public class SelectExpression implements IExpression {
    private final List<IExpression> columns = new ArrayList<>();

    public void addCols(IExpression col) {
        columns.add(col);
    }

    @Override
    public String interpret(Context context) {
        StringJoiner interpretResult = new StringJoiner(", ");
        for (IExpression col : columns) {
            interpretResult.add(col.interpret(context));
        }
        context.getResult().append("返回").append(interpretResult).append("列");
        return interpretResult.toString();
    }
}
